﻿package Modules.MouseCursorModule
{
	import Modules.PlayerModule.InventoryModule.Tables.SeedItem;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	public class PlantSeedTool extends Tool
	{
		var highlightedCropDisplayObject:MovieClip;
		var seed:SeedItem;
		
		public function PlantSeedTool(mySeed:SeedItem)
		{
			super();
			seed = mySeed
		}
		
		//Plant seed checks here!
		override public function toolUp(event:MouseEvent):void{
			
			super.toolUp(event);
			
			if(click){
				
				if(highlightedCropDisplayObject != null){
					
					//The following function call should be activated in the avatar
					//It is here just to speed up the development
					//Trust me, watching the avatar walk around during development is a pain.
					//Remember to ask the avatar to walk to the plot before planting the seed.
					highlightedCropDisplayObject.plantSeed(seed);
				}
			}		
		}
		
		//Tool move function to highlight the valid objects
		override public function toolMove(event:MouseEvent):void{
			
			if(highlightedCropDisplayObject != null){
				highlightedCropDisplayObject.unhighlightObject();
				highlightedCropDisplayObject = null;
			}
			
			if(event.target is CropDisplayObject){
				
				highlightedCropDisplayObject = (event.target as CropDisplayObject)
					
				//Only allow the selection/highlighting if and only if the seed object has not been planted before
				if(!highlightedCropDisplayObject.seedItem){
					highlightedCropDisplayObject.highlightObject();
				}
			}
		}
	}	
}